class BrowserHistory {
  private stack: string[]
  private index: number
  constructor(homepage: string) {
    this.stack = [homepage]
    this.index = 0
  }

  visit(url: string): void {
    this.stack.splice(this.index + 1)
    this.index += 1
    this.stack.push(url)
  }

  back(steps: number): string {
    const spill: boolean = this.index - steps < 0
    this.index = spill ? 0 : this.index - steps
    return this.stack[this.index]
  }

  forward(steps: number): string {
    const spill: boolean = this.index + steps > (this.stack.length -1)
    this.index = spill ? this.stack.length - 1 : this.index + steps
    return this.stack[this.index]
  }
}